<template>
  <div>

        <el-button style="float: left" type="success" @click="clientAddNew">添加</el-button>

        <el-button style="float: left" type="success" @click="exportExcel">导出数据</el-button>


    <br>
    <br>
    <el-divider></el-divider>

    <el-table :data="clientArr">
      <el-table-column type="index" label="编号"></el-table-column>
      <el-table-column prop="name" label="姓名" align="center" width="120"></el-table-column>
      <el-table-column prop="gender" label="性别" align="center" width="120"></el-table-column>
      <el-table-column prop="number" label="身份证号" align="center" width="120"></el-table-column>
      <el-table-column prop="birth" label="出生年月" align="center" width="120"></el-table-column>
      <el-table-column prop="phone" label="联系方式" align="center" width="120"></el-table-column>
      <el-table-column prop="backgroundDisease" label="基础病" align="center" width="120"></el-table-column>
      <el-table-column prop="emergencyContactPhone" label="紧急联系人" align="center" width="120"></el-table-column>
      <el-table-column prop="address" label="地址" align="center" width="120"></el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
<!--          <el-button type="danger" @click="openDeleteConfirm(scope.row)">修改</el-button>-->
          <el-button type="danger" @click="openDeleteConfirm(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
import axios from "axios";

import TokenAxios from "@/http/TokenAxios";
import BaseUrl from "@/http/BaseUrl";


export default {
  methods: {
    clientAddNew(){
      this.$router.push("/personal/clientAddNew");
    },
    clientList(){
      debugger
      TokenAxios.get(BaseUrl.INFORMATIOON+'/patients/').then((response)=>{
        if (response.data.state===20000){
          debugger
          this.clientArr=response.data.data;
          console.log(response.data.data)
          console.log(this.clientArr)
        }
      })
    },
    exportExcel(){//导出excel文档//window.open("http://localhost:29080/patients/downExcel")
      TokenAxios.get2(BaseUrl.INFORMATIOON+"/patients/getExcel").then(res =>{
        const url = URL.createObjectURL(res.data);
        const link = document.createElement('a');
        link.href = url;
        link.download = '就诊人信息.xlsx';
        link.click();
        URL.revokeObjectURL(url);
      }).catch(error =>{
        console.log(error);
      })
    },
    openDeleteConfirm(client) {
      let message = '此操作将永久删除【' + client.name + '】类别，是否继续？';
      this.$confirm(message, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.handleDelete(client);
      }).catch(() => {
      });
    },
    handleDelete(client) {
      let url = 'http://localhost:29080/patients/delete/' + client.id ;
      console.log('url = ' + url);

      TokenAxios.post(url).then((response) => {
        let jsonResult = response.data;
        if (jsonResult.state == 20000) {
          this.$message({
            message: '删除成功！',
            type: 'success'
          });
          this.clientList();
        } else {
          this.$message.error(jsonResult.message);
        }
      });
    },

  },
  data() {
    return {
      clientArr:[],
    }
  },
  mounted(){
    this.clientList();
  }



}





</script>
